/*
 * @Author: 飞越疯人院 353362604@qq.com
 * @Date: 2022-09-08 13:51:32
 * @LastEditors: 飞越疯人院 353362604@qq.com
 * @LastEditTime: 2023-01-11 11:07:39
 * @FilePath: \adminstration\src\Common\Modal\ThrModal.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// !!! 三级弹窗层
import { Drawer } from 'antd'
import { useState, useEffect } from 'react'
import { useEventEmitter, useBoolean } from 'ahooks'
import { DeleteConfirmModal } from './Modal'

// 更多菜单
import { SelectModal } from './MoreModal/SelectModal'
import { FormModal } from './MoreModal/FormModal'
import { TinyMce } from './MoreModal/TinyMce'
import { LabTemplate } from './MoreModal/LabTemplate'
import { CementMixing } from './MoreModal/CementMixing'
import { LabAsphalt } from './MoreModal/LabAsphalt'
import { Link } from './MoreModal/Link'
import { AttachmentList } from './MoreModal/AttachmentList'

// 三级页菜单引入
import { TestType } from './ThrModalList/TestType'
import { LabReportTemplates } from './ThrModalList/LabReportTemplates'
import { SampleEnclosure } from './ThrModalList/SampleEnclosure'
import { SampleParameter } from './ThrModalList/SampleParameter'
import { SampleParameterDetails } from './ThrModalList/SampleParameterDetails'
import { SampleReport } from './ThrModalList/SampleReport'
import { FileManagement } from './ThrModalList/FileManagement'
import { PushFlowConfig } from './ThrModalList/PushFlowConfig'
import { Organization } from './ThrModalList/Organization'
import { EnterpriseFiles } from './ThrModalList/EnterpriseFiles'
import { EnterpriseImage } from './ThrModalList/EnterpriseImage'
import { ProjectFormItemValue } from './ThrModalList/ProjectFormItemValue'
import { ProjectSetUp } from './ThrModalList/ProjectSetUp'
import { ProjectFundYearPlan } from './ThrModalList/ProjectFundYearPlan'
import { ProjectFundYearStat } from './ThrModalList/ProjectFundYearStat'
import { Supervise } from './ThrModalList/Supervise'
import { ProjectSchedule } from './ThrModalList/ProjectSchedule'
import { SecurityProblem } from './ThrModalList/SecurityProblem'
import { SecurityDetails } from './ThrModalList/SecurityDetails'
import { SecurityDetailAttachment } from './ThrModalList/SecurityDetailAttachment'
import { SecurityDetailAttachmentDetail } from './ThrModalList/SecurityDetailAttachmentDetail'
import { PersonGroup } from './ThrModalList/PersonGroup'
import { FileManagementTiny } from './ThrModalList/FileManagementTiny'
import { BeamProduceRecordDetail } from './ThrModalList/BeamProduceRecordDetail'
import { BeamProduceRecordPersonGroup } from './ThrModalList/BeamProduceRecordPersonGroup'
import { BeamQualityReport } from './ThrModalList/BeamQualityReport'
import { LabStressMachineDetails } from './ThrModalList/LabStressMachineDetails'
import { ProjectCompanyInfos } from './ThrModalList/ProjectCompanyInfos'
import { ProjectSetUpOperation } from './ThrModalList/ProjectSetUpOperation'
import { ProjectSetUpPayment } from './ThrModalList/ProjectSetUpPayment'
import { ProjectCompanyMonthReport } from './ThrModalList/ProjectCompanyMonthReport'
import { ProjectCompanyMonthReportAttachment } from './ThrModalList/ProjectCompanyMonthReportAttachment'
import { ProjectCompanyMonthReportAttachmentList } from './ThrModalList/ProjectCompanyMonthReportAttachmentList'
import { ProjectBuildList } from './ThrModalList/ProjectBuildList'
import { CameraGroupDetail } from './ThrModalList/CameraGroupDetail'
import { CementMixingStationDetails } from './ThrModalList/CementMixingStationDetails'
import { LabAsphaltDetails } from './ThrModalList/LabAsphaltDetails'
import { FileManagementLink } from './ThrModalList/FileManagementLink'
import { MeterageAttachment } from './ThrModalList/MeterageAttachment'
import { PlanStatAttachment } from './ThrModalList/PlanStatAttachment'
import { GantryCraneCameras } from './ThrModalList/GantryCraneCameras'
import { DeviceCamera } from './ThrModalList/DeviceCamera'

// !!! 可用三级页模板
const SecondaryList = {
    SelectModal,
    FormModal,
    TinyMce,
    LabTemplate,
    CementMixing,
    LabAsphalt,
    Link,
    AttachmentList,
}

// !!! 三级页数据
const ThrModalListData = {
    TestType,
    LabReportTemplates,
    SampleEnclosure,
    SampleParameter,
    SampleParameterDetails,
    SampleReport,
    FileManagement,
    PushFlowConfig,
    Organization,
    EnterpriseFiles,
    EnterpriseImage,
    ProjectFormItemValue,
    ProjectSetUp,
    ProjectFundYearPlan,
    ProjectFundYearStat,
    Supervise,
    ProjectSchedule,
    SecurityProblem,
    SecurityDetails,
    SecurityDetailAttachment,
    SecurityDetailAttachmentDetail,
    PersonGroup,
    FileManagementTiny,
    BeamProduceRecordDetail,
    BeamProduceRecordPersonGroup,
    BeamQualityReport,
    LabStressMachineDetails,
    ProjectCompanyInfos,
    ProjectSetUpOperation,
    ProjectSetUpPayment,
    ProjectCompanyMonthReport,
    ProjectCompanyMonthReportAttachment,
    ProjectCompanyMonthReportAttachmentList,
    ProjectBuildList,
    CameraGroupDetail,
    CementMixingStationDetails,
    LabAsphaltDetails,
    FileManagementLink,
    MeterageAttachment,
    PlanStatAttachment,
    GantryCraneCameras,
    DeviceCamera,
}

export const ThrModalList = async ({ upDataEvent, value, data, Permission }) => {
    const ClientData = JSON.parse(localStorage.getItem('ClientData'))
    let dataList = await ThrModalListData[value]({ upDataEvent, data, ClientData, Permission })
    return dataList
}

export const ThrModal = ({ Off, ThrConfig, actionRef, RefreshEvent, Permission, className, PPPEvent }) => {
    // 三级页配置参数
    const [ThrConfigData, setThrConfigData] = useState()
    // 三级页状态
    const [ThrBoxState, { setTrue: ThrBoxTrue, setFalse: ThrBoxFalse }] = useBoolean(false)
    // 额外弹出层标题与路径
    const [ModalRecord, setModalRecord] = useState()
    // 修改参数
    const [ModifyData, setModifyData] = useState()
    // 额外参数
    const [AdditionalData, setAdditionalData] = useState()
    // 删除数据确认窗口
    const [DeleteModalState, { setTrue: DeleteModalTrue, setFalse: DeleteModalFalse }] = useBoolean(false)
    // 二级页操作列表
    const upDataEvent = useEventEmitter()
    upDataEvent.useSubscription(({ type, value, data, additional }) => {
        switch (type) {
            case 'ThrModal':
                setThrConfigData({ value, data })
                ThrBoxTrue()
                break
            case 'delete':
                setAdditionalData(additional)
                setModalRecord(data)
                setModifyData(value)
                DeleteModalTrue()
                break
            default:
                break
        }
    })

    // 初始化数据
    const [CurrentData, setCurrentData] = useState()
    useEffect(() => {
        const getCurrentData = async () => {
            const { value, data } = ThrConfig
            const dataList = await ThrModalList({ upDataEvent, value, data, Permission })
            setCurrentData(dataList)
        }
        getCurrentData()
    }, [ThrConfig, actionRef, upDataEvent, Permission])

    return (
        <>
            {CurrentData && (
                <Drawer
                    className={`ModalTitle ${className}`}
                    title={CurrentData.type}
                    placement="right"
                    onClose={Off}
                    open={true}
                    destroyOnClose
                    maskClosable={false}
                    width={CurrentData.width}
                >
                    {(() => {
                        const Template = SecondaryList[CurrentData.classification]
                        console.log('打开三级页', CurrentData.classification)
                        return (
                            <Template
                                CurrentData={CurrentData}
                                upDataEvent={upDataEvent}
                                data={ThrConfig.data}
                                actionRef={actionRef}
                                Off={Off}
                                backfill={CurrentData.backfill}
                                RefreshEvent={RefreshEvent}
                                className={className}
                                PPPEvent={PPPEvent}
                            />
                        )
                    })()}
                </Drawer>
            )}
            {ThrBoxState && (
                <ThrModal
                    ThrConfig={ThrConfigData}
                    actionRef={actionRef}
                    Off={ThrBoxFalse}
                    RefreshEvent={RefreshEvent}
                    className={className}
                />
            )}

            {/* 删除弹出层 */}
            {DeleteModalState && (
                <DeleteConfirmModal
                    Off={DeleteModalFalse}
                    actionRef={actionRef}
                    ModalRecord={ModalRecord}
                    ModifyData={ModifyData}
                    AdditionalData={AdditionalData}
                />
            )}
        </>
    )
}
